import * as path from 'path';
import nested from 'postcss-nested';
import babel from 'rollup-plugin-babel';
import commonjs from 'rollup-plugin-commonjs';
import htmlTemplate from 'rollup-plugin-fill-html';
import nodeResolve from 'rollup-plugin-node-resolve';
import postcss from 'rollup-plugin-postcss';
import { terser } from 'rollup-plugin-terser';
import tslint from 'rollup-plugin-tslint';
import typescript from 'rollup-plugin-typescript2';

const DIST_DIR = 'dist';

export default [
  {
    input: 'src/index.ts',
    output: {
      name: 'DocWriter',
      file: path.join(DIST_DIR, 'doc-writer.js'), // DIST_DIR + 'doc-writer.js',
      sourcemap: false,
      format: 'umd',
    },
    plugins: [
      htmlTemplate({
        template: 'src/template.html',
        filename: 'index.html',
      }),
      tslint(),
      typescript(),
      postcss({
        extract: DIST_DIR + '/styles/doc-writer.min.css',
        inject: false,
        minimize: {
          safe: true,
        },
        plugins: [nested()],
        extensions: ['.pcss', '.css'],
      }),
      nodeResolve({
        jsnext: true,
        main: true,
      }),
      babel({
        babelrc: false,
        comments: false,
        sourceMap: false,
        exclude: 'node_modules/**',
        extensions: ['.js', '.ts'],
      }),
      commonjs(),
      terser(),
    ],
  },
];
